import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";

const routes: Array<RouteRecordRaw> = [
    {
        path: "/",
        name: "Login",
        meta: {
            title: "登录",
            keepAlive: true
        },
        component: () => import("@/views/Login/index.vue"),
    },
    {
        path: "/layout",
        name: "Layout",
        component: () => import("@/views/Layout/index.vue"),
        children: [
            {
                path: "/home",
                name: "Home",
                meta: {
                    title: "首页",
                    // keepAlive: true
                },
                component: () => import("@/views/Home/index.vue"),
            },
            {
                path: "/personCenter",
                name: "PersonCenter",
                meta: {
                    title: "个人中心",
                    // keepAlive: true
                },
                component: () => import("@/views/PersonCenter/index.vue"),
            },
        ]
    },

];
const router = createRouter({
    history: createWebHashHistory(),
    routes
});
router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数，在进入路由前执行
    if (to.meta.title) {//判断是否有标题
        // @ts-ignore
        document.title = to.meta.title
    }
    next()  //执行进入路由，如果不写就不会进入目标页
});
export default router;
